/*
 * @Description:
 * @Author: dh
 * @Date: 2021-09-28 14:19:19
 * @LastEditors: dh
 * @LastEditTime: 2021-09-29 09:17:49
 */

self.addEventListener('install', event => {
	console.log('正在注册sw2')
})

self.addEventListener('activate', event => {
	console.log('正在激活sw2')
})

self.addEventListener('message', event => {
	console.log('sw2-收到page消息', event.data)

	// 监听sw1
	event.ports[0].onmessage = e => {
		console.log('sw2-收到sw1消息:', e.data)
	}

	// 发送给sw1
	event.ports[0].postMessage('this message is from sw2.js, to sw1')

	// 发送给page
	event.source.postMessage('this message is from sw2.js, to page')
})
